package com.one.tank;

import java.awt.*;

//爆炸效果
public class Bomb {
    //爆炸状态常量
    public static final int BOMB_STATE_FREE = 0;
    public static final int BOMB_STATE_RUNNING = 1;
    //爆炸效果宽度
    private int width = 20;
    //爆炸效果高度
    private int height = 20;
    //爆炸效果X坐标
    private int x;
    //爆炸效果Y坐标
    private int y;
    //爆炸效果状态
    private int state = BOMB_STATE_FREE;
    //爆炸进度，根据它来决定显示哪种爆炸形状（-1-不显示任何爆炸形状，0-准备显示，1-显示第一种爆炸形状，2-显示第二种爆炸形状，3-显示第三种爆炸形状）
    public int bombProgress = -1;

    /**
     * 构造函数
     * @param x 爆炸效果左上角X坐标
     * @param y 爆炸效果左上角Y坐标
     */
    public Bomb(int x, int y) {
        this.x = x;
        this.y = y;
    }
    /**
     * 准备爆炸。
     */
    public void prepareBomb() {
        this.state = BOMB_STATE_RUNNING;
        //爆炸进度准备显示
        this.bombProgress = 0;
    }

    /**
     * 爆炸效果重置
     */
    public void reSet() {
        this.setX(-100);
        this.setY(-100);
        this.state = BOMB_STATE_FREE;
        //爆炸进度重置
        this.bombProgress = -1;
    }

    /**
     * 画爆炸
     * 每帧显示一种形状，共三种，即3帧结束爆炸
     */
    public void drawBomb(Graphics g) {
        //进度开始启动
        this.bombProgress++;
        //根据进度显示某种爆炸产生的效果
        switch(this.bombProgress) {
            case 1:
                g.setColor(Color.WHITE);
                g.fillRoundRect(this.x+5, this.y+5, 20, 20, 10, 10);
                g.fillOval(this.x+10, this.y+10, 10, 30);
                g.setColor(Color.YELLOW);
                g.drawOval(this.x+10,this.y,10,30);
                g.setColor(Color.WHITE);
                g.fillOval(this.x, this.y+10, 30, 10);
                g.setColor(Color.YELLOW);
                g.drawOval(this.x, this.y+10, 30, 10);
                break;
            case 2:
                g.setColor(Color.WHITE);
                g.fillOval(this.x + 12,this.y + 5,6,20);
                g.setColor(Color.YELLOW);
                g.drawOval(this.x + 12,this.y + 5,6,20);
                g.setColor(Color.WHITE);
                g.fillOval(this.x + 5,this.y + 12,20,6);
                g.setColor(Color.YELLOW);
                g.drawOval(this.x + 5,this.y + 12,20,6);
                break;
            case 3:
                g.setColor(Color.WHITE);
                g.fillOval(this.x + 10,this.y + 10,10,10);
                g.setColor(Color.YELLOW);
                g.drawOval(this.x + 10,this.y + 10,10,10);
                break;
            default:
                this.reSet();
                break;
        }
    }
    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }
}
